﻿//
// Created by francklinson on 2021/3/28.
//

#include "VintagePort.h"

VintagePort::VintagePort()
= default;

VintagePort::VintagePort(const char *br, const char *st, int b, const char *nn, int y) : Port(br, st, b)
{
    nickname = new char[strlen(nn) + 1];
    strcpy(nickname, nn);
    year = y;

}

VintagePort::VintagePort(const VintagePort &vp) : Port(vp)
{
    delete nickname;
    nickname = new char[strlen(vp.nickname) + 1];
    strcpy(nickname, vp.nickname);
    year = vp.year;
}

VintagePort &VintagePort::operator=(const VintagePort &vp)
{
    if (this == &vp)
        return *this;
    cout << "Vintage copy " << endl;
    Port::operator=(vp);
    delete nickname;
    nickname = new char[strlen(vp.nickname) + 1];
    strcpy(nickname, vp.nickname);
    year = vp.year;
    return *this;
}

void VintagePort::Show() const
{
    cout << "Vintage: " << endl;
    Port::Show();
}

ostream &operator<<(ostream &os, const VintagePort &vp)
{
    cout << (Port &) vp;
    cout << ", nickname: " << vp.nickname << " year: " << vp.year << endl;
    return os;
}
